<template>
  <div>
    <el-form :inline="true" :model="rechargeform" class="demo-form-inline">
      <el-form-item label="患者名称">
        <el-input v-model="rechargeform.name" placeholder="请输入项目名称"></el-input>
      </el-form-item>
      <el-form-item label="备注号码">
        <el-input v-model="rechargeform.phone" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="rechargeform.status" placeholder="用户状态">
          <el-option label="正常" value="0"></el-option>
          <el-option label="停用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="rechargeform.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择起始日期">
        </el-date-picker>
        <el-date-picker
          v-model="rechargeform.endsTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择截止日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="rechargeList">
      <el-table-column label="患者编号" prop="doctId" align="center" type="hidden"></el-table-column>
      <el-table-column label="患者编号" prop="id" align="center"></el-table-column>
      <el-table-column label="患者姓名" prop="name"align="center"></el-table-column>
      <el-table-column label="余额" prop="money"align="center"></el-table-column>
      <el-table-column label="手机号码" prop="phone"align="center"></el-table-column>
      <el-table-column label="状态" prop="status"align="center"></el-table-column>
      <el-table-column label="创建时间" prop="date"align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="rechargeway(scope.row)">充值</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%">
      <el-input type="hidden" v-model="recharge.id"></el-input>
      <el-input type="hidden" v-model="recharge.doctName"></el-input>
      <el-input type="hidden" v-model="recharge.doctId"></el-input>
      患者名称：<el-input type="text" v-model="recharge.name" style="width: 300px"></el-input><br><br>
      充值金额：<el-input type="text" v-model="recharge.money"style="width: 300px"></el-input><br><br>
      充值方式：<el-select v-model="recharge.way" placeholder="充值方式">
      <el-option label="在线" value="online"></el-option>
      <el-option label="现金" value="cash"></el-option>
    </el-select>
      <br><br>
      手机号码：<el-input type="text" v-model="recharge.phone"style="width: 300px"></el-input><br><br>
      备注：<el-input type="text" v-model="recharge.remark"style="width: 300px"></el-input><br><br>
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addrecharge">确 定</el-button>
    </el-dialog>
  </div>
</template>

<script>
  import {Listrecharge,RechargePatient} from '@/api/system/patientRecharge';
  import { getUserProfile } from "@/api/system/user";
  export default {
    name: "index",
    data() {
      return {
        title: '充值',
        dialogVisible: false,
        rechargeList: [],
        recharge: {
          id:'',
          doctName:'',
          name: '',
          money:'',
          status:0,
          phone:'',
          remark:'',
          way:'',
          doctId:''
        },
        rechargeform: {
          name: '',
          phone:'',
          status:0,
          startTime:'',
          endsTime:'',
          doctName:''
        },
      }
    },
    methods: {
      rechargeway: function (s) {
        this.recharge =s;
        this.title="修改患者";
        this.dialogVisible=true;
      },
      getList(){
        Listrecharge(this.rechargeform).then(response => {
            console.log(this.rechargeform);
            this.rechargeList = response;
          }
        );
      },
      addrecharge:function () {
        console.log(this.recharge);
        //js 增加病人方法
        RechargePatient(this.recharge);
        //查询所有
        this.getList();
        this.dialogVisible=false;
      },
      getUser:async function(){
        await getUserProfile().then(response => {
          this.rechargeform.doctName = response.data.nickName;
          console.log(this.rechargeform.doctName);
        })
        this.getList();
      },

      onSubmit() {
        Listrecharge(this.rechargeform).then(response => {
            console.log(response);
            this.rechargeList = response;
          }
        );
      },
    },
    mounted() {
      this.getUser();
    },
  }
</script>

<style scoped>

</style>
